package day2;

import java.io.*;

//缓冲流+新版try-catch实现文件复制
public
class TestCopy3 {
    public static
    void main(String[] args) {
        try (
            FileInputStream fis = new FileInputStream("D:\\IO\\movie\\1.mp4");
            FileOutputStream fos = new FileOutputStream("D:\\IO\\movie\\11.mp4");
            BufferedInputStream bis = new BufferedInputStream(fis);
            BufferedOutputStream bos = new BufferedOutputStream(fos))
            {
//            File f=new File("D:\\IO\\movie\\1.mp4");
            int len;
            byte[] bytes = new byte[1024];
//            long size = f.length();
//            long i=0;
//            long start = System.currentTimeMillis();
            while ((len = bis.read(bytes)) != -1) {
//                i += len;
                bos.write(bytes,0,len);
//                System.out.printf("当前进度：%.5f%%\n",(i*100.0/size));
            }
            long end = System.currentTimeMillis();
//            System.out.println("复制完毕，耗时：" + (end - start) + "ms");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
